﻿using Resto.CostControl.Core.Facade.SupplierModule.FacadeObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Resto.CostControl.Core.Facade.SupplierModule.DataTransferObject;
using Enterprise.Framework.Core.Container;
using System.Collections.Generic;
using System.Linq;
using Resto.CostControl.Core.Facade.MaterialModule.FacadeObject;
using Resto.CostControl.Core.Facade.MaterialModule.DataTransferObject;
using Resto.CostControl.Core.Enums;

namespace Resto.CostControl.UnitTest.MaterialModule
{


    /// <summary>
    ///这是 MaterialProcessFOTest 的测试类，旨在
    ///包含所有 MaterialProcessFOTest 单元测试
    ///</summary>
    [TestClass()]
    public class MaterialProcessFOTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///AddMaterialProcess 的测试
        ///</summary>
        [TestMethod()]
        public void AddMaterialProcessTest()
        {
            MaterialProcessFO target = ObjectCreator.Create<MaterialProcessFO>();
            MaterialProcessDTO supplierContractDTO = new MaterialProcessDTO()
            {
                Code = "a2",
                ProcessDate = DateTime.Now,                
            };

            List<MaterialProcessItemDTO> list = new List<MaterialProcessItemDTO>();
            MaterialProcessItemDTO item1 = new MaterialProcessItemDTO()
            {
                RawMaterialId = 1,
                SemiMaterialId = 2,
                ExpectedPickCount = 100m,
                ExpectedStorageCount = 80m,
            };
            MaterialProcessItemDTO item2 = new MaterialProcessItemDTO()
            {
                RawMaterialId = 3,
                SemiMaterialId = 4,
                ExpectedStorageCount = 200m,
                ExpectedPickCount = 150m,
            };
            list.Add(item1);
            list.Add(item2);

            supplierContractDTO.Items = list.ToArray();

            target.AddMaterialProcess(supplierContractDTO,MaterialProcessState.Order);
            //Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///AddMaterialProcess 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateMaterialProcessTest()
        {
            MaterialProcessFO target = ObjectCreator.Create<MaterialProcessFO>();
            MaterialProcessDTO supplierContractDTO = target.GetMaterialProcessDTO(1);
            List<MaterialProcessItemDTO> list = supplierContractDTO.Items.ToList();

            list.RemoveAt(0);

            foreach (MaterialProcessItemDTO item in list)
            {
                item.ActualPickCount = item.ExpectedPickCount;
                item.ActualStorageCount = item.ExpectedStorageCount;
            }

            MaterialProcessItemDTO item1 = new MaterialProcessItemDTO()
            {
                RawMaterialId = 5,
                SemiMaterialId = 6,
                ExpectedPickCount = 100m,
                ActualPickCount = 100m,
                ExpectedStorageCount = 80m,
                ActualStorageCount = 80m,
            };
            MaterialProcessItemDTO item2 = new MaterialProcessItemDTO()
            {
                RawMaterialId = 7,
                SemiMaterialId = 8,
                ExpectedPickCount = 100m,
                ActualPickCount = 100m,
                ExpectedStorageCount = 80m,
                ActualStorageCount = 80m,
            };
            list.Add(item1);
            list.Add(item2);

            supplierContractDTO.Items = list.ToArray();


            target.UpdateMaterialProcess(supplierContractDTO,MaterialProcessState.Storage);
            //Assert.Inconclusive("无法验证不返回值的方法。");
        }
    }
}
